package cn.cxy.tagview

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import kotlinx.android.synthetic.main.view_tags.view.*

class TagView(
    context: Context,
    attrs: AttributeSet?
) : LinearLayout(context, attrs) {

    init {
        initView(context)
    }

    private fun initView(context: Context) {
        LayoutInflater.from(context).inflate(R.layout.view_tags, this, true)
    }

    fun setData(tagList: List<String>) {
        tagList.forEach {
            containerLayout.addView(genView(it))
        }
    }

    private fun genView(tag: String): View? {
        val textView =  LayoutInflater.from(context).inflate(R.layout.view_tag_item, this, false) as TextView
        textView.text = tag
        return textView
    }
}
